<template>
	<view class="page" :style="{minHeight:windowHeight+'px'}">
		<!-- <view class="top-head">
			<view class="head-l">
				<image src="../../../static/jiaotou1.png" @click="gotoPage('/pages/home/home')"></image>
			</view>
			<view class="head-title">今日车单</view>
			<view class="head-r"></view>
		</view> -->
		<!-- <block v-for="(item,index) in 1" :key="index" >
			<view class="list-item">
				<view class="item-info">
					<view>
						永州 林灵 -> 东莞 麻涌
					</view>
					<text>刚刚</text>
				</view>
				<view class="item-info1">
					<view>
						<text>16座</text>
						<text>|</text>
						<text>到付</text>
					</view>
					<view>约1km</view>
				</view>
				<view class="item-price">
					￥<text>39000</text> /趟
				</view>
				<view class="user-wrap">
					<view class="user-box">
						<view class="user-avatar">
							<image src="../../../static/app/logo.png" mode=""></image>
						</view>
						<view class="user-info">
							<view class="user-name">
								<text>桂林大聪网络有限公司</text>
								<image src="../../../static/app/vip1.png" mode=""></image>
							</view>
							<text>交易234 好评率95%</text>
						</view>
					</view>
					<view class="item-btn" @click="gotoToday(index)">
						去抢单
					</view>					
				</view>
				<view class="list-line"></view>
			</view>
		</block> -->
		<!-- <view class="list" v-for="(item,index) in singleCar" :key="index" >
			<view class="list-item">
				<view class="item-info">
					<view>
						{{item.starting}} -> {{item.destination}}
					</view>
					<text>{{item.issueTime}}</text>
				</view>
				<view class="item-info1">
					<view>
						<text>{{item.seat}}</text>
						<text>|</text>
						<text>{{item.payType}}</text>
					</view>
					<view>约1km</view>
				</view>
				<view class="item-price">
					￥<text>{{item.price}}</text> /趟
				</view>
				<view class="user-wrap">
					<view class="user-box">
						<view class="user-avatar">
							<image :src="item.companyLogo" mode=""></image>
						</view>
						<view class="user-info">
							<view class="user-name">
								<text>{{item.companyName}}</text>
								<image src="../../../static/app/vip1.png" mode=""></image>
							</view>
							<text>交易{{item.number}} 好评率{{item.feedBack}}%</text>
						</view>
					</view>
					<view class="item-btn" @click="gotoToday(type,item.singleCarId)">
						去抢单
					</view>					
				</view>
				<view class="list-line"></view>
			</view>
		</view> -->
		<view class="list" v-for="(item,index) in orderList" :key="index" >
			<view class="list-item">
				<view class="item-info">
					<view class="item-info-add">
						<view class="item-info-add-con">{{item.star_address.b_name}}</view> <text class="item-info-add-jt">-></text> <view class="item-info-add-con">{{item.end_address.d_name}}</view>
					</view>
					<text class="item-info-add-days">用车{{item.days}}天</text>
				</view>
				<view class="item-info1">
					<view>
						<text>{{item.passenger}}人</text>
						<text>|</text>
						<text v-if="item.settlement_type==1">下团结</text>
						<text v-if="item.settlement_type==2">月结</text>
					</view>
					<view>约{{item.total_km}}km</view>
				</view>
				<view class="item-price">
					￥<text>{{item.price}}</text> 
				</view>
				<view class="user-wrap">
					<view class="user-box">
						<view class="user-avatar">
							<image v-if="item.user.avatarUrl==''" src="../../../static/dafaulthead2.png" mode=""></image>
							<image v-else :src="item.user.avatarUrl" mode=""></image>
						</view>
						<view class="user-info">
							<view class="user-name" v-if="item.attestation.types==1" @click="phoneCall(item.attestation.phone)">
								<text>{{item.attestation.phone}}</text>
								<!-- <text v-else>{{item.attestation.person_name}}</text> -->
								<!-- <image :src="item.user.avatarUrl" mode=""></image> -->
							</view>
							<view class="user-name" v-else @click="phoneCall(item.attestation.person_name)">
								<text>{{item.attestation.person_phone}}</text>
								<!-- <image :src="item.user.avatarUrl" mode=""></image> -->
							</view>
							<!-- <text>交易{{item.tradesNum}} 好评率{{item.feedBack}}%</text> -->
						</view>
					</view>
					<view class="item-btn" @click="gotoToday(item.id)">
						去抢单
					</view>					
				</view>
				<view class="list-line"></view>
			</view>
		</view>
		<!-- 没有记录 -->
		<view class="null d-c-c p30" v-if="orderList.length == 0 ">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<view v-else v-show="isLoadMore">
			<uni-load-more :loadingType="loadding"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				isLoadMore: false, //是否加载中
				page: 1,
				pagesize: 10,
				loadding:0,
				isShow: false,
				/* 数据列表 */
				listDate:0,
				type:'',//车单的类型
				singleCar:[
					{ 
						singleCarId:1001,
						starting:'永州 林灵',
						destination:' 东莞 麻涌',
						issueTime:'刚刚',
						seat:'16座',
						payType:'到付',
						price:3999,
						companyName:'桂林大聪网络有限公司',
						companyLogo:'../../../static/app/logo.png',
						feedBack:'99',
						number:'66',
					},
					{
						singleCarId:1002,
						starting:'永州 林灵',
						destination:' 东莞 麻涌',
						issueTime:'刚刚',
						seat:'18座',
						payType:'到付',
						price:6999,
						companyName:'桂林大聪网络有限公司',
						companyLogo:'../../../static/app/logo.png',
						feedBack:'99',
						number:'88',
					},
				],
				windowHeight:'',
				car_id:'',
				orderList:[],
				order_type:'',//1当日，2三日内，3一个月内
			};
		},
		onLoad(e) {
			uni.getSystemInfo({
				success: (res) => {
					this.windowHeight = res.windowHeight;
				}
			});
			if(e.select == 1){
				this.order_type = e.order_type;
				this.getData();
			}			
		},
		onPullDownRefresh() {
			this.page = 1;
			this.orderList = [];
			this.getData();
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.page += 1
				this.getData();
			}
		},
		methods:{
			phoneCall(phone) {
				let self = this;
				uni.makePhoneCall({
					phoneNumber:phone
				});
			},
			gotoToday(id){
				uni.navigateTo({
					url:'/pages/home/grab/grab?select=1&&id='+ id
				})
			},
			/*跳转页面*/
			gotoPage(path) {
				let self = this;
				if(path.startsWith('/')){
					uni.navigateTo({
						url: path
					});
				}else{
					self[path]();
				}
			},
			/*获取车单数据*/
			getData() {
				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._get('order.CarOrder/get_order_list',
				{
					day_type:3,
					order_type:self.order_type,
					page:self.page
				}, 
				
				function(res) {
					//self.orderList = res.data.list.data;
					if (res.data.list.data) {
						self.orderList = self.orderList.concat(res.data.list.data)
						if (res.data.list.data.length < res.data.list.per_page) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
							self.isLoadMore = true
							self.loadding = 2
						} else {
							self.isLoadMore = false
						}
					} else {
						self.isLoadMore = true
						self.loadding = 2
					}
					uni.hideLoading();
				});
			},
		}
	}
</script>

<style lang="scss">
@import 'monthCar.scss'
</style>
